import demo1.BookList;
import demo2.Student;
import demo2.Admini;
import java.util.Scanner;
import demo2.Person;
public class Test {

    public static Person logic(){
        System.out.println("********** 欢迎来到图书系统小练习 **********");
        System.out.println("1-->管理员  0-->学生");
        System.out.println("请输入您的身份");
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        sc.nextLine();
        System.out.println("请输入您的姓名");
        String name=sc.nextLine();
        if(n==1){
            return new Admini(name);

        }
        if(n==0){
            return new Student(name);
        }
        return null;

    }

    public static void studentWork(Person person, BookList book){
        System.out.println(person.name+"请输入您的操作");
        Scanner sc=new Scanner(System.in);
        while(sc.hasNextInt()) {

            int n = sc.nextInt();
            if (n == 1) {
                book.find();
            }
            if (n == 2) {
                book.jieYue();
            }
            if(n==3){
                book.guiHuan();
            }
            if (n == 4) {
                book.show();
            }
            if(n==0){
                book.exit();
            }
            System.out.println("1：查找图书");
            System.out.println("2：借阅图书");
            System.out.println("3：归还图书");
            System.out.println("4：显示图书");
            System.out.println("0:退出系统");
        }

    }
    public static void adminiWork(Person person, BookList book){
        System.out.println(person.name+"请输入您的操作");
        Scanner sc=new Scanner(System.in);
        while(sc.hasNextInt()) {

            int n = sc.nextInt();
            if (n == 1) {
                book.add();
            }
            if (n == 2) {
                book.del();
            }
            if(n==3){
                book.find();
            }
            if (n == 4) {
                book.show();
            }
            if(n==0){
                book.exit();
            }
            System.out.println("1：增加图书");
            System.out.println("2：删除图书");
            System.out.println("3：查找图书");
            System.out.println("4：退出系统");
        }

    }

    public static void main(String[] args) {

             Person person=logic();
             BookList bookList=new BookList();
              int choice=person.function();
              if(choice==0){
                  studentWork(person,bookList);
              }
              if(choice==1){
                  adminiWork(person,bookList);
              }


    }
}
